﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.EnterpriseServices;
using System.Data;
using Npgsql;
using NpgsqlTypes;
using Tuto.Objects;

namespace Tuto.DAL
{
    /// <summary>
    ///     A student at the level of DLL : This implements a CRUD
    /// </summary>
    public class Etudiant 
    {
        /// <summary>
        ///     Adds a new Object
        /// </summary>
        /// <param name="_obj"></param>
        /// <returns></returns>
        public int create(Dictionary<string, object> fields)
        {
            int id;

            id = DALObject.runSQLInsert("tuto_etudiant", fields);
            
            return id;
        }

        /// <summary>
        ///     Updates a rows of Etudiant
        /// </summary>
        /// <param name="_obj"></param>
        /// <returns></returns>
        public int update(Dictionary<string, object> fields, int etudiantId)
        {
            int result;

            result = DALObject.runSQLUpdate("tuto_etudiant", fields, etudiantId);

            return result;
        }

        /// <summary>
        ///     Reads and Maps an Object
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataSet read(int id)
        {
            DataSet _dataSet = new DataSet();

            List<string> table = new List<string>();
            table.Add("tuto_etudiant");
            List<string> cols = new List<string>();
            List<string> num_ops = new List<string>();
            num_ops.Add("=");
            List<string> log_ops = new List<string>();
            Dictionary<string, object> constrainte = new Dictionary<string, object>();
            constrainte.Add("id", id);
            
            _dataSet = DALObject.runSQLSelect(table, cols, constrainte, num_ops, log_ops);

            return _dataSet;
        }

        public int delete(int id)
        {
            int result;

            List<string> num_ops = new List<string>();
            num_ops.Add("=");
            List<string> log_ops = new List<string>();
            Dictionary<string, object> constrainte = new Dictionary<string, object>();
            constrainte.Add("id", id);
            result = DALObject.runSQLDelete("tuto_etudiant", constrainte, num_ops, log_ops);

            return result;
        }

    }
}
